package com.shyroke.daydayzhuanapi.mapper;

import com.shyroke.daydayzhuanapi.dto.LabelDto;
import com.shyroke.daydayzhuanapi.dto.LabelLabelListDto;
import com.shyroke.daydayzhuanapi.entity.LabelEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class LabelMapper {
    @Autowired
    private ModelMapper modelMapper;

    public LabelDto entityToDto(LabelEntity labelEntity) {
        return modelMapper.map(labelEntity,LabelDto.class);
    }

    public LabelLabelListDto entityToAdminDto(LabelEntity e) {
        LabelLabelListDto dto = modelMapper.map(e, LabelLabelListDto.class);
        if(e.getType() != null) {
            dto.setTypeName(e.getType().getTypeName());
            dto.setTypeId(e.getType().getId());
        }
        return dto;
    }
}
